package UIFree.controls
{
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import flash.events.Event;
	import flash.geom.Rectangle;

	public class uif_radioGroup extends uif_ecomponent {
		private var _selectItem: Object;
		public function uif_radioGroup(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:String='') {
			super(parent, ax, ay, awidth, aheight, styleClass);
			addEvent(uif_baseCheckBox.CHECKED, function(e: Event): void {
				_selectItem = (e.target as uif_component)._data;
				e.stopPropagation();
			});
		}
		
		public function get selectItem(): Object {
			return _selectItem;
		}
		
		public function assignList(list: Array, titleField: String='name', curIndex: int = 0): void {
			removeChilds();
			var inner: Rectangle = getInner();
			var i:int = 0;
			for each (var item: Object in list) {
				var cbButton: uif_checkbox = new uif_checkbox(this, inner.x, inner.y + i * 20, inner.width, 20, style.button);
				cbButton.text = item[titleField];
				cbButton._data = item;
				if (i == curIndex) cbButton.checked = true;
				i++;
			}
			
		}
	}
}